var express = require('express');
var router = express.Router();
const Holders = require('../dao/com_holders_dao');


router.get('/jj/list/com/:offset/:limit', async function (req, res) {
    const resData = {
        code: 0, msg: 'success', data: []
    }
    const offset = req.params.offset
    const limit = req.params.limit
    resData.data = await Holders.listJJ(parseInt(offset), parseInt(limit))
    res.json(resData).end();
});


/**
 * 获取指定机构持有的公司列表
 */
router.post('/jj/list/com/of/:offset/:limit', async function (req, res) {
    const offset = req.params.offset
    const limit = req.params.limit
    const jj_name = req.body.jj_name
    const resData = {
        code: 0, msg: 'success', offset: parseInt(offset), data: []
    }

    resData.data = await Holders.findAllStockHoldByHolderName(parseInt(offset), parseInt(limit), jj_name)
    res.json(resData).end();
});
/**
 * 获取机构所持的股票列表
 */
router.get('/jj/list/hold/count/:offset/:limit', async function (req, res) {
    const offset = req.params.offset
    const limit = req.params.limit
    const resData = {
        code: 0, msg: 'success', offset: parseInt(offset), data: []
    }
    resData.data = await Holders.findJJHoldCount(parseInt(offset), parseInt(limit))
    res.json(resData).end();
});

router.get('/jj/count', async function (req, res) {
    const resData = {
        code: 0, msg: 'success', data: []
    }
    const jj_name = req.body.jj_name
    resData.data = await Holders.countAllStockHoldByHolderName(jj_name)
    res.json(resData).end();
});
module.exports = router;
